﻿@inject AppState AppState

<Panel Left="8" Top="8" Width="325" Height="60" BackColor="SystemColors.ControlLight">
    @* Input area *@
    <Label Left="8" Top="8" Width="180" Text="What's to be done?" />
    <TextBox Left="8" Top="32" Width="230" @bind-Text="newText" />
    <Button Top="8" Left="250" Height="50" Width="50" Text="&Add" OnClick="@AddItem" />
</Panel>

<Panel Left="8" AutoScroll="true" Width="325" Height="300" Top="80" BackColor="SystemColors.ControlLight">
    @* List of todos *@
    @for (int i = 0; i < AppState.Items.Count; i++)
    {
        <TodoEntry Item="@AppState.Items[i]" Top="@(i * 50 + 8)" />
    }
</Panel>

@code
{
    string newText;

    void AddItem()
    {
        AppState.Items.Add(new TodoItem { Text = newText });
        newText = null;
    }
}
